﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using Infrastructure.Aspect.Dynamic;

namespace Infrastructure.Web.Controls
{

    [ToolboxData("<{0}:DynamicBoundField runat=server></{0}:DynamicBoundField>")]
    public class DynamicBoundField : System.Web.UI.WebControls.BoundField
    {
        protected override object GetValue(System.Web.UI.Control controlContainer)
        {
            if (!this.DesignMode)
            {
                var target = controlContainer as GridViewRow;
                if (target != null && target.DataItem is CustomXmlExpandoObject)
                {
                    var expando = target.DataItem as CustomXmlExpandoObject;
                    var data = expando.GetMember(this.DataField);
                    return data;
                }
                else
                {
                    return null;
                }
            }
            else
                return null; 
        }
    }
}

